home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / shape.lha / shape / slist.c < prev    next >
Text File  |  1993-08-08  |  947b  |  77 lines

  1. include "slist.h"
  2. include <stream.h>
  3. include <stdlib.h>
  4.  
  5. nt slist::insert(ent a)
  6.  
  7.    if (last)
  8.        {
  9. last->next = new slink(a, last->next);
  10. }
  11.    else
  12. {
  13. last = new slink(a, 0);
  14. last->next = last;
  15. }
  16.    return 0;
  17.  
  18.  
  19. nt slist::append(ent a)
  20.  
  21.    if (last)
  22. {
  23. last = last->next = new slink(a, last->next);
  24. }
  25.    else
  26. {
  27. last = new slink(a, 0);
  28. last->next = last;
  29. }
  30.    return 0;
  31.  
  32.  
  33. nt slist::get()
  34.  
  35.    if (last == 0)
  36. slist_handler("get from empty slist");
  37.    slink *f = last->next;
  38.    ent r = f->e;
  39.    if (f == last)
  40. {
  41. last = 0;
  42. }
  43.    else
  44. {
  45. last->next = f->next;
  46. }
  47.    delete f;
  48.    return r;
  49.  
  50.  
  51. oid slist::clear()
  52.  
  53.    slink *l = last;
  54.    if (l == 0) return;
  55.    do {
  56. slink *ll = last;
  57. l = l->next;
  58. delete ll;
  59.    } while (l != last);
  60.    last = 0;
  61.  
  62.  
  63. tatic void default_error(char *s)
  64.  
  65.    cerr << s << "\n";
  66.    exit(1);
  67.  
  68.  
  69. FC slist_handler = default_error;
  70.  
  71. FC set_slist_handler(PFC handler)
  72.  
  73.    PFC rr = slist_handler;
  74.    slist_handler = handler;
  75.    return rr;
  76.  
  77.